package hot100.logos61To70;

import java.util.Stack;

/**
 * @author logos
 * date 2025/7/17 12:21
 * @version v1.0
 * @Package hot100.logos61To70
 */
public class logos70 {

    /**
     * 70. 最小栈
     * https://leetcode.cn/problems/min-stack/?envType=study-plan-v2&envId=top-100-liked
     */

    class MinStack {

        private Stack<int[]> stack = new Stack<>();

        public MinStack() {
            stack.clear();
        }

        public void push(int val) {
            int[] tmp = new int[2];
            tmp[0] = val;
            if (stack.isEmpty()) {
                tmp[1] = val;
            } else {
                if (val < stack.peek()[1]) {
                    tmp[1] = val;
                } else {
                    tmp[1] = stack.peek()[1];
                }
            }
            stack.push(tmp);
        }

        public void pop() {
            stack.pop();
        }

        public int top() {
            return stack.peek()[0];
        }

        public int getMin() {
            return stack.peek()[1];
        }
    }
}
